function [beta export] = estimate_unadj(M)

  global omega_coeffs seomega_coeffs;
  omega_coeffs = []; seomega_coeffs = [];

  data.firmid = M(:,1);
  data.year = M(:,2);
  data.lnVA = M(:,3);     % Value added
  data.lnY = M(:,11);     % Output
  data.lnqempl = M(:,4);  % Quality adjusted labor from Mincer
  data.Llnqempl = M(:,12);% lag    
  data.lnL = M(:,10);     % Employment
  data.L = exp(data.lnL);
  data.LlnL = M(:,13);    
  data.lnInp = M(:,5);    % Intermediate useage
  data.LlnInp = M(:,14);  
  data.Inv = M(:,6);      % Investment
  data.lnK = M(:,7);
  data.LlnK = M(:,15);
  data.Ex = M(:,8);       % Export dummy
  data.nace = M(:,9);     % Nace 2 digit code

  % Worker variables
  firmvars = 16;
  data.sex = M(:,firmvars+4);      % Gender shares
  data.ftenure = M(:,firmvars+5:firmvars+7);% Tenure shares
  data.edu = M(:,firmvars+8:firmvars+11);   % Education shares
  data.exp = M(:,firmvars+12:firmvars+15);  % Experience shares
  data.lnw = M(:,firmvars+16);     % Average wage
  
  % Which labor variable do we want to use
  data.lnlabor = data.lnL;
  data.Llnlabor = data.LlnL;
  
  % Which outcome variable to use
  data.y = data.lnVA;
  
  data.Inv(data.Inv<=0) = NaN;

  data.n = length(data.y);
  disp('Number of firm-year obs'); 
  disp(data.n);

  % Simple OLS (used as starting values)

  X = [ones(data.n,1) data.lnlabor data.lnK];                  % Regressors
  b_ols = inv((X'*X))*X'*data.y;                       % Coeff. estimates
  se = sqrt(diag((data.y-X*b_ols)'*(data.y-X*b_ols)/(data.n-size(X,2))*inv(X'*X)));      % Standard error
  clear X;

  % ----------------------------------------------------
  % STAGE I
  % ----------------------------------------------------
  clear i lnK l poly1 poly2 poly3 poly4 X lambda b;
  %i = data.lnInp;          % Ackerberg and LP
  i = log(data.Inv);        % Olley-Pakes
  lnK = data.lnK;
  l = data.lnlabor;
  Dyear = dummyvar(data.year-1995);
  data.Dyear = Dyear(:,2:end);

  % Polynomial in (i,k,m)
  poly1 = [data.Dyear data.Dyear.*repmat(i,1,9) data.Dyear.*repmat(lnK,1,9)];
  poly2 = [i i.^2 i.^3 lnK lnK.^2 lnK.^3 i.*lnK i.^2.*lnK i.*lnK.^2];     
  poly3 = [data.Ex data.Ex.*i data.Ex.*lnK];
  
  X = [ones(data.n,1) data.lnlabor poly1 poly2 poly3]; 
  [b,ci,r,rint,stats]  = regress(data.y,X);
  betaL = b(2);
  
  alpha = .05;
  t = tinv(1-alpha/2,data.n-length(b));
  se_unadj1 = (ci(:,2)-ci(:,1)) ./ (2*t); % Standard Error

  lambda = X*b - betaL*data.lnlabor;

  % ----------------------------------------------------
  % STAGE II
  % ----------------------------------------------------
 
  gmmf = @(beta) Ackerberg_gmm(beta,lambda,data);

  % Test function
  %gmmf([.3 .3])

  b0 = b_ols(3);  
  options = optimset('Display','iter','TolFun',1e-8,'TolX',1e-8,'MaxFunEvals',5e7,'MaxIter',10000);
  [betaK,fval,exitflag,output,grad,hessian] = fminunc(gmmf,b0,options);       

  beta = [betaL betaK omega_coeffs];

  pr = data.y - beta(1)*data.lnlabor - beta(2)*data.lnK;
  export = [data.firmid data.year data.nace pr];
end
